package util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class CommonDao {
    private static CommonDao commonDao = new CommonDao();

    public static CommonDao getInstance(){
        return commonDao;
    }
    public int count(Connection connection, String s) throws SQLException {
        //创建集合类对象，用于保存所有元组代表的School对象
        //TreeSet按compare(Object o)方法指定的顺序排列
        StringBuilder sql_select = new StringBuilder("select * from " + s);
        //如果有条件，则生成条件子句，并附加到主语句的后面
        List<Condition> conditionList = null;
        String whereClause = Condition.toWhereClause(conditionList);
        sql_select.append(whereClause);
        //获取Teacher中的元组总数
        //获得查询教师的语句对象
        PreparedStatement pstmt_select = connection.prepareStatement(sql_select.toString());
        ResultSet resultSet = pstmt_select.executeQuery();
        int sum = 0;
        //遍历resultSet
        while (resultSet.next()){
            sum ++;
        }
        return sum;

    }
}
